package 其他.获取8位不重复的随机数;

import java.util.HashSet;

/**
 * 随机0-9 组成一个8位不重复的数字的字符串, 产生4个这样的字符串, 也是互相不重复的
 */
public class GetRandomString {
    public static void main(String[] args) {
        HashSet<Long> set = new HashSet<>();
        HashSet<String> stringSet = new HashSet<>();
        while (stringSet.size()<4){
            set.clear();
            while (set.size()<8){
                long round = Math.round(Math.random() * 9);
                set.add(round);
            }
            StringBuilder str = new StringBuilder();
            for (Long item : set) {
                str.append(item);
            }
            stringSet.add(str.toString());
        }
        for (String s : stringSet) {
            System.out.println(s);
        }
    }
}
